//
//  Device.swift
//  TuneMate
//
//  Created by 丸子 on 2023/11/23.
//

import Foundation
import UIKit
import FCUUID


class Device {
    static let IDFA = uuidFormatForDevice()
    static let BUILD_VERSION = (Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String)?.int ?? 0
    static let VERSION_NAME = (Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String) ?? ""
    static let displayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String
    static let bundleName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String
    
    private static func uuidFormatForDevice() -> String {
          let uuid = NSMutableString(string: FCUUID.uuidForDevice())
          [6, 12, 16, 22].forEach{ index in
              uuid.insert("-", at: index)
          }
          return uuid.string.uppercased()
        
      }
}

extension NSString {

    var string: String {
        return self as String
    }
}

// 项目运行环境
enum ProjectEnvironment {
    case product    // 生产环境
    case dev       // 测试环境
}

class Configs {
    private let pageCacheKey = "pageMode"
    static let `default` = Configs()
    private(set) var runEnv: ProjectEnvironment = .dev   // 运行环境(在config方法参数中修改)
    private init() { }
    /// 项目启动配置
    /// - Parameters:
    ///   - env: 环境
    func run(_ env: ProjectEnvironment) {
        assert(Device.bundleName != nil, "请配置Bundle Name参数")
        guard let bundleName = Device.bundleName else { return }
        self.runEnv = env
    }
    
}

